package com.example.socketchat.controller;

import com.example.socketchat.model.ChatMessage;
import com.example.socketchat.service.ChatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/chat")
public class ChatController {

    @Autowired
    private ChatMessageService chatMessageService;

    /**
     * 获取指定用户的消息列表
     */
    @GetMapping("/messages/{userId}")
    public List<Object> getUserMessages(@PathVariable String userId,
                                    @RequestParam(defaultValue = "0") int start,
                                    @RequestParam(defaultValue = "10") int limit) {
        return chatMessageService.getUserMessages(userId, start, start + limit - 1);
    }

    /**
     * 获取指定ID的消息
     */
    @GetMapping("/message/{messageId}")
    public ChatMessage getMessageById(@PathVariable String messageId) {
        return chatMessageService.getMessageById(messageId);
    }
} 